package LeetCode;

import java.util.ArrayList;
import java.util.List;
import java.util.Stack;

public class Num1441 {
    public List<String> buildArray(int[] target, int n) {
        Stack<Integer> stack=new Stack<>();
        List<String> list=new ArrayList<>();
        int flag=0;
        for (int i = 1; i < n; i++) {
            if(flag<target.length) {
                stack.push(i);
                list.add("Push");
            }
            if(flag<target.length && target[flag]!=stack.peek()){
                stack.pop();
                list.add("Pop");
                flag--;
            }
            flag++;
        }
        return list;
    }
}
